﻿using Ewk.Math.Numerics;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Ewk.Math.Algebra.UnitTests
{
    [TestClass]
    public class VectorComplexUnitTests : VectorUnitTestsBase<Complex>
    {
        [TestMethod]
        public void VectorComplex_Add_performs_an_add_to_each_element()
        {
            var vector1 = CreateVector(new Complex(1, 0), new Complex(2, 1), new Complex(3, 2));
            var factor = new Complex(2, 1);

            vector1.Add(factor);

            Assert.AreEqual(new Complex(3, 1), vector1[0].Value);
            Assert.AreEqual(new Complex(4, 2), vector1[1].Value);
            Assert.AreEqual(new Complex(5, 3), vector1[2].Value);
        }

        [TestMethod]
        public void VectorDouble_CrossProduct_performs_a_multiplication_on_each_element()
        {
            var vector1 = CreateVector(Complex.I, Complex.Zero, Complex.Zero);
            var vector2 = CreateVector(Complex.Zero, 2* Complex.I, Complex.Zero);

            var crossProduct = Vector<Complex>.CrossProduct(vector1, vector2);

            Assert.AreEqual(Complex.Zero, crossProduct[0].Value);
            Assert.AreEqual(Complex.Zero, crossProduct[1].Value);
            Assert.AreEqual(-2 * Complex.One, crossProduct[2].Value);
        }

        [TestMethod]
        public void VectorComplex_Norm_computes_the_euclidian_norm_of_the_vector()
        {
            var vector1 = CreateVector(new Complex(0, 3), new Complex(0, 4));
            var norm = vector1.Norm;

            var real = System.Math.Round(norm.Value.Real, 14);
            var imaginary = System.Math.Round(norm.Value.Imaginary, 14);
            Assert.AreEqual(0.0, real);
            Assert.AreEqual(5.0, imaginary);
        }
    }
}
